/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __IRESOURCE_H__
#define __IRESOURCE_H__

#pragma once

enum eResourceType
{
	RESTYPE_UNKNOWN = 0,
	RESTYPE_CAMERA,
	RESTYPE_FONT,
	RESTYPE_MATERIAL,
	RESTYPE_MESHGEOMETRY,
	RESTYPE_SHADEREFFECT,
	RESTYPE_SKYBOX,
	RESTYPE_TEXTURE,
	RESTYPE_TRANFORMABLE,
	RESTYPE_SCENENODE
};

/**
 * \ingroup CoreEngine
 *
 * The IResource interface.<br>
 * Specifies objects that store lots of memory inside the graphic card. <br>
 * i.e. Textures, Meshes, Materials, Shaders, ...
 *
 * \date 03-28-2007
 *
 * \author juckel
 *
 */
class DLL_EXPORT IResource
{
public:
	IResource();
	virtual ~IResource();
	/// Used to reset the data of a resource. 
	/// DirectX can loose resources that are able to be reset using this function.
	virtual void reset() = 0;

	/// Used to release the data memory of a resource
	virtual void release() = 0;

	/// Returns the current reference count
	inline const int getRef() const 
	{
		return m_uiReferences;
	}

	/// Increments the reference count by one
	inline IResource* addRef()
	{
		// Increase ref count
		++m_uiReferences;
		return this;
	}

	/// Decrements the reference count by one
	IResource* destroy()
	{
		if (m_uiReferences < -1) return NULL;
		// Delete the object, if ref count is 0
		if ( --m_uiReferences <= 0 ) {
			delete this;
			return NULL;
		}
		return this;
	}

	virtual unsigned int getType() = 0;

protected:
	int                 m_uiReferences;
	static unsigned int ms_uiTotalObjects;
};

#endif
